package com.jintu.portal.service.scheduler;

import com.github.ziplet.filter.compression.CompressingFilter;
import com.jintu.portal.config.SysConfigWatcher;
import org.quartz.*;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author very
 */
@Configuration
public class SchedulerConfiguration {

    @Bean
    public JobDetail sysConfigWatcherTaskDetail() {
        return JobBuilder.newJob(SysConfigWatcher.class).withIdentity("sysConfigWatcher").storeDurably().build();
    }

    @Bean
    public Trigger sysConfigWatcherTaskTrigger() {
        CronScheduleBuilder scheduleBuilder = CronScheduleBuilder.cronSchedule("*/1 * * * * ?");
        return TriggerBuilder.newTrigger().forJob(sysConfigWatcherTaskDetail()).withIdentity("sysConfigWatcher").withSchedule(scheduleBuilder).build();
    }

    @Bean
    public FilterRegistrationBean<CompressingFilter> loggingFilter(){

        FilterRegistrationBean<CompressingFilter> registrationBean = new FilterRegistrationBean<>();
        registrationBean.setFilter(new CompressingFilter());
        registrationBean.addUrlPatterns("/risk/gateway/pushData");
        return registrationBean;
    }
}
